import Vue from 'vue'
import VueRouter from 'vue-router'
import recommend from '../views/recommend.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: "/",
    redirect: "/recommend"
  },
  {
    path: '/recommend',
    name: 'recommend',
    component: recommend
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    // component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  },
  {
    path:"/userInfo",
    name:"userInfo",
    component:()=>import("../views/userinfo.vue"),
    beforeEnter:(to,from,next)=>{
      let login = window.localStorage.getItem("token");
      if(!login){
        next("/login");
        return;
      }else{
        next();
      }
    }
  },
  {
    path:"/login",
    name:"login",
    component:()=>import("../components/base/login.vue")
  },
  {
    path: "/recommend/search",
    name: "search",
    component: () => import("../components/base/search.vue")
  },
  {
    path: "/recommend/mv",
    name: "mv",
    component: () => import("../components/base/mv.vue")
  },
  {
    path: "/singer",
    name: "singer",
    component: () => import("../views/singer.vue")
  },
  {
    path: "/rank",
    name: "rank",
    component: () => import("../views/rank.vue")
  },
  {
    path:"/rank/ranklist",
    name:"ranklist",
    component:()=>import("../components/rank/ranklist.vue")
  },
  {
    path:"/singer/singerlist",
    name:"singerlist",
    component:()=>import("../components/rank/singerlist.vue")
  },
]

const router = new VueRouter({
  // mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
